$(document).ready(function(){
	
	$("#b_bialog").show();
	 
	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#add_lawtypeID');
			});
  		}
	});
	
	$.ajax({
  		type: "post",
 		url: "hmk/getLawNature_findAll.action",
  		success:function(data){
  			$.each(data.lawNatureList,function(i,n){
  				$("<option value="+n.lnId+">"+n.lnName+"</option>").appendTo('#add_lawNatureID');
			});
  		}
	});
	
	
	$("#dialog-form").dialog({
		autoOpen: false,
		width: 460,
		modal: true,
		resizable: false,
	    close: function() {
			$("#FJID").text("");
			$("#FJNameID").text("");
			
			//getPaList();
			var realName=$(window.frames["uploadFrame"].document).find("#RealNameID").text();
			var objectName=$(window.frames["uploadFrame"].document).find("#ObjectNameID").text();
			//alert(realName);
			//alert(objectName);
			$("#FJID").text(objectName);
			$("#FJNameID").text(realName);
			$("#b_bialog").hide();
			$("#paListDIV").show();
			//$("#FJID").text(myFile.crtName);
			//$("#FJNameID").text(myFile.originName);
			
	 	}
	});
	
	$("#b_bialog").click(function(){
		$("#uploadFrame").attr("src","/ag/hmk/myupload.jsp");
		$('#dialog-form').dialog('open'); //open dialog
	});
	
	/////////////////////
	$("#acceptForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单
        var typeID=$('#add_lawtypeID option:selected').val();
		var lawNatureID=$('#add_lawNatureID option:selected').val();
		var lawName=$('#lawNameID').val();
		var lawDetail=$('#lawDetailID').val();
		var lawKey = $("#lawkeyID").val();
		var FJID =$("#FJID").text();
		var FJNameID =$("#FJNameID").text();
		
		if(FJID!=null && FJID.length!==0 && FJNameID!=null && FJNameID.length!==0  ){
			$.ajax({
  				 type: "post",
 				url: "hmk/saveLaw_saveLaw.action",
 				data:{
 				  	typeID1:typeID,lawNature1:lawNatureID,lawName1:lawName,lawDetail1:lawDetail,
 				 	 kwStr1:lawKey,fileID1:FJID,fileNameID1:FJNameID
 					 },
  				success:showData
		 	});
		  }else{
		  	alert("请先添加附件");
		  }
		  
        },
		rules: {
			'add_lawtypeID':'required',
			'add_lawNatureID':'required',
			'lawNameID':'required'
			
		} ,
		messages: {
			'add_lawtypeID':"*必须选",
			'add_lawNatureID':"*必须选",
			'lawNameID':"*必须选"
			
		}
	});
	////////////////
	
	
	function showData(data){
		if(data.ajaxRST=='1'){
			alert("保存成功！");
			$('#mainFrame',window.parent.document).attr('src','/ag/hmk/LawAdd.jsp');
		}else{
			alert("保存失败！");
		}
	}
	
	$('#CANCEL_LAW').click(function(){
		$('#mainFrame',window.parent.document).attr('src','/ag/hmk/LawAdd.jsp');
	});
	
	
});


	function getPaList(){	
		var timestamp = Date.parse(new Date());
		$.get("hmk/session_findPaList.action?ts="+timestamp,null,getPaListRst);
	}

	function getPaListRst(data){
		if(data.paList!=null){
			$.each(data.paList,function(i,n){
				$("#FJID").text(n.paId);
				$("#FJNameID").text(n.paName);
			});
			$("#b_bialog").hide();
			$("#paListDIV").show();
		}
	}


	function delFJ(v){
		alert("删除成功");
		$("#FJID").text("");
		$("#FJNameID").text("");
		$("#b_bialog").show();
		$("#paListDIV").hide();
		
		//var timestamp = Date.parse(new Date());
		//$.get("hmk/session_DeleteSession.action?ts="+timestamp,null,delSessionOK);
	}

	function delSessionOK(data){
		alert("删除成功");
		$("#FJID").text("");
		$("#FJNameID").text("");
		$("#b_bialog").show();
		$("#paListDIV").hide();
	}